import Loading from '@/pages/Loading'
import Error from '@/pages/Error'

export default function lazyLoadView (AsyncView) {
    const AsyncHandler = () => ({
      component: (()=>{
        return new Promise((resolve,reject)=>{
            setTimeout(function () {
              AsyncView.then(e=>resolve(e)).catch(()=>reject())
            }, 0)
        })
    })(),
      loading: Loading,
      error: Error,
      delay: 200,
      timeout: 10000
    });
    return Promise.resolve({
      functional: true,
      render (h, { data, children }) {
        return h(AsyncHandler, data, children);
      }
    });
  }